package com.adcc.loadsheet.movingdata.util;

import com.adcc.aoc.devLib.common.log.Log;
import org.joda.time.DateTime;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * Created by AN on 2020-05-15.
 */
public class FileUtil {

    private static String filename="lastDay.txt";

    public static boolean saveLastDay(String day){
        try{
            File file=new File(filename);
            FileOutputStream out=new FileOutputStream(file);
            byte[] str=day.getBytes();
            for(int i=0;i<str.length;i++){
                out.write(str[i]);
            }
            out.close();
            return true;
        }catch (Exception ex){
            Log.error(FileUtil.class,"保存最后舱单名单入库时间出错",ex);
            return false;
        }
    }

    public static DateTime getLastDay(){
        try{
            File file=new File(filename);
            if(!file.exists()){
                return null;
            }
            String result="";
            FileInputStream in=new FileInputStream(file);
            int len=in.available();
            for(int i=0;i<len;i++){
                result+=(char)in.read();
            }
            DateTime lastday=DateTime.parse(result);
            return lastday;
        }catch (Exception ex){
            Log.error(FileUtil.class,"获取最后舱单名单入库时间出错",ex);
            return null;
        }
    }
}
